package com.huluobo.high3videoproject.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import com.flyco.tablayout.SlidingTabLayout;
import com.huluobo.high3videoproject.R;
import com.huluobo.high3videoproject.mvp.search.view.NearByFragment;
import com.huluobo.high3videoproject.mvp.video.view.VideoListFragment;

import java.util.ArrayList;

public class MainFragment extends Fragment {
    private ArrayList<Fragment> fragments;

    private SlidingTabLayout slidingTabLayout;
    private ViewPager viewPager;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
                             @Nullable Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_main, container, false);
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        initView(view);
        initData();
    }

    private void initData() {
        fragments = new ArrayList<>();
        fragments.add(new VideoListFragment());//视频列表页面
        fragments.add(new NearByFragment());//附近页面

        slidingTabLayout.setViewPager(viewPager, new String[]{"视频", "附近"}, getActivity(), fragments);
    }

    private void initView(View view) {
        slidingTabLayout = view.findViewById(R.id.main_tabLayout);
        viewPager = view.findViewById(R.id.main_ViewPager);
    }
}
